<template>
  <!-- <div class="container">
    Home
    <button @click="setToken">存储token</button>
  </div> -->
  <div class="container">
    <!-- 文章分类栏 -->
    <van-tabs swipeable animated v-model="activeIndex">
      <van-tab :key="item.id" v-for="item in channelList" :title="item.name">
        <!-- 可滚动内容区域 -->
        <ArticleList :channelId="item.id"></ArticleList>
      </van-tab>
    </van-tabs>
    <!-- 右侧图标 -->
    <span class="bar_btn" @click="show = true">
      <van-icon name="wap-nav"></van-icon>
    </span>
    <!-- 放到根元素结束之前 -->
    <ChannelEdit
      :activeIndex.sync="activeIndex"
      :myChannel="channelList"
      v-model="show"
    />
  </div>
</template>

<script>
import request from '../../utils/request'
// import { getChannelApi } from '../../api/home'
import ArticleList from './components/articleList'
import ChannelEdit from './components/channel-edit.vue'
import { getUserChannelApi } from '../../api/channel'
export default {
  name: 'home-index',
  components: {
    ArticleList,
    ChannelEdit
  },
  created () {
    // 测试request封装
    // request({ url: 'announcements' }).then(res => {
    //   console.log('页面获取到的：', res.data)
    // })
    // 测试错误
    request.get('user/profile').then(res => {
      console.log(res)
    })
    this.getChannel()
    // 测试组件是否缓存
    // console.log(1)
  },
  data () {
    return {
      activeIndex: 0, // 当前选中页签的索引值
      show: false,
      channelList: []
    }
  },
  methods: {
    // setToken () {
    //   this.$store.commit('setToken', { token: 2, refresh_token: 3 })
    // }
    async getChannel () {
      const { data } = await getUserChannelApi()
      console.log(data)
      this.channelList = data.channels
    }
  }
}
</script>

<style scoped lang='less'>
.van-tabs {
  height: 100%;
  display: flex;
  flex-direction: column;
  // 自定义tab样式
  /deep/ .van-tabs__wrap {
    height: 36px;
    padding-right: 36px;
    .van-tab {
      line-height: 36px;
    }
    .van-tabs__line {
      background-color: #fc6627;
      height: 2px;
    }
  }
  /deep/ .van-tabs__content {
    flex: 1;
    overflow: hidden;
  }
  /deep/ .van-tab__pane {
    height: 100%;
    // 控制列表区域可滚动
    .scroll-wrapper {
      height: 100%;
      overflow-y: auto;
    }
  }
}
.bar_btn {
  width: 36px;
  height: 35px;
  position: absolute;
  top: 0;
  right: 0;
  font-size: 20px;
  text-align: center;
  line-height: 40px;
  box-shadow: -6px -6px 8px #ddd;
}
</style>
